<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if(!session_id()) { session_start(); }

//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.

if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}

//get some variables:
$requested_attn_id = $_SESSION['current_attendee_id'];
if (isset($_GET['action'])) $action = $_GET['action'];

//process the form variables.

if (isset($_POST['amount']))
	$values['amount']=floatval($_POST['amount']);
if (isset($_POST['type']))
	$values['type']=$_POST['type'];
	$values['entered_by']=$_SESSION['attendee_id'];
	$values['for_attendee_id']=$_SESSION['current_attendee_id'];
if (isset($_POST['confirmed']))
	$values['confirmed']=$_POST['confirmed'];

if (empty($_POST['amount']) || empty($_POST['type'])) {
	do_html_header('Problem Processing', staysmall, $uny);
	echo 'You must specify both a payment amount and type!<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
	}


if (!isset($values['confirmed'])) {
	do_html_header('Confirm Payment', staysmall, $uny);
	if ($values['amount'] > 0) {
		$trans_type = '<span class="redtext">Credit</span>';
		}
	if ($values['amount'] < 0) {
		$trans_type = '<span class="redtext">Refund</span>';
		}
	$user_info = get_user_info($values['for_attendee_id']);
	echo "<h1>Transaction Details</h1>";
	echo "<strong>Name:</strong> ".$user_info['first_name']." ".$user_info['last_name']."<br />\n";
	echo "<strong>Attendee_id:</strong> ".$user_info['attendee_id']."<br />\n";
	echo "You are about to $trans_type $".abs($values['amount'])." to the above account of type ".ucfirst($values['type'])."\n";
	echo "<form method=post action=\"".$_SERVER['PHP_SELF']."\">\n";
	echo '<input type="hidden" name="confirmed" value="Y">';
	print_hidden_form_fields($values);
	echo "<input type=submit value=\"Process\">\n</form>";
	do_html_footer(news);
	exit;
	}

if ($values['confirmed'] == 'Y') {
	insert_trans_log($values['entered_by'], $values['for_attendee_id'], $values['amount'], $values['type']);
	update_attendee_amount_paid($values['for_attendee_id'], $values['amount']);
	$trans_attendee_id = $values['for_attendee_id'];
	header("Location: ".$conf['base_path']."registration/attendee_home.php?attendee_id=$trans_attendee_id");
	exit;
	}

?>